import React, { useEffect, useState } from 'react';
import { Breadcrumb, Button, Card, Input, Radio, Table, Image, Modal, Form, message, Popconfirm, notification, DatePicker } from 'antd';
import { RedoOutlined, MoreOutlined, DeleteOutlined, AudioOutlined, PlusOutlined, PlusCircleOutlined } from '@ant-design/icons';
import '../../style/healthAdd.scss'
import axios from 'axios';
import { useNavigate } from 'react-router-dom';
import { add_hlist } from '../../utils/api2'


function HealthAdd(props) {
  var navigate = useNavigate()
  const onFinish = (values) => {
    console.log(values);
    if (values.name == '' || values.con == '' || values.temperature == '' || values.time == '' || values.time2 == '') {
      notification.warning({ message: '有行程信息未填写' })
    } else {
      add_hlist({ name: values.name, con: values.con, temperature: values.temperature, Jtime: time.$y + '-' + (time.$M + 1) + '-' + time.$D, Utime: time2.$y + '-' + (time2.$M + 1) + '-' + time2.$D + ' ' + time2.$H + ' : ' + time2.$m }).then((res) => {
        console.log(res.data);
      })
      notification.success({ message: '行程信息添加成功' })
      navigate('/index/healthymange')
    }

  };
  const config = {
    rules: [
      {
        type: 'object',
        required: true,
        message: 'Please select time!',
      },
    ],
  };
  var [time, setTime] = useState([])
  var change = (value) => {
    console.log(value);
    setTime(value)
  }
  var [time2, setTime2] = useState({})
  var change2 = (value) => {
    console.log(value);
    setTime2(value)
  }
  return (
    <div className='addHealth'>
      <Breadcrumb>
        <Breadcrumb.Item>
          <a href='/index/home'>
            首页
          </a>
        </Breadcrumb.Item>
        <Breadcrumb.Item>
          <a href="/index/tripmanage">行程信息</a>
        </Breadcrumb.Item>
        <Breadcrumb.Item>
          <span>添加行程</span>
        </Breadcrumb.Item>
      </Breadcrumb>
      <div className="site-card-border-less-wrapper">
        <Card
          title="添加行程信息"
          className='card'
          bordered={false}
          style={{
            width: 1250,
          }}
        >
          <Form
            labelCol={{ span: 6 }}
            wrapperCol={{ span: 18 }}
            onFinish={onFinish}
            className="addform"


          >
            <Form.Item
              label="学号"
              name="con"
              rules={[{ required: true, message: '输入学号' }]}


            >
              <Input placeholder='输入学号' className="input" />
            </Form.Item>

            <Form.Item
              label="姓名"
              name="name"
              rules={[{ required: true, message: '输入姓名' }]}

            >
              <Input placeholder='输入姓名' className="input" />
            </Form.Item>

            <Form.Item
              label="体温"
              name="temperature"
              rules={[{ required: true, message: '输入体温' }]}

            >
              <Input placeholder='输入体温' className="input" />
            </Form.Item>

            <Form.Item name="date-picker" label="添加监测时间" {...config}>
              <DatePicker onChange={change} />
            </Form.Item>
            <Form.Item name="date-time-picker" label="添加上传时间" {...config}>
              <DatePicker showTime format="YYYY-MM-DD HH:mm:ss" onChange={change2} />
            </Form.Item>

            <Form.Item className='submit'>
              <Button type="primary" htmlType="submit" className='router'>
                添加行程信息
              </Button>
            </Form.Item>
          </Form>
        </Card>
      </div>

    </div>
  );
}

export default HealthAdd;